<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateRoleTable extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('role', [
            'id' => true,
            'primary_key' => ['id'],
            'comment' => '角色表',
            'engine' => 'InnoDB',
            'encoding' => 'utf8mb4',
        ]);
        $table->addColumn('name', 'string', [
            'limit' => 20,
            'null' => false,
            'default' => '',
            'comment' => '角色名称',
        ])->addColumn('description', 'string', [
            'limit' => 255,
            'null' => true,
            'comment' => '角色描述',
        ])->addColumn('status', 'boolean', [
            'null' => false,
            'default' => 1,
            'comment' => '状态:0=禁用,1=启用',
        ])->addColumn('sort', 'integer', [
            'null' => false,
            'default' => 0,
            'comment' => '排序',
        ])->addColumn('create_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'comment' => '创建时间',
        ])->addColumn('update_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'update' => 'CURRENT_TIMESTAMP',
            'comment' => '更新时间',
        ])->addIndex(['name'], [
            'name' => 'uk_name',
            'unique' => true,
        ])->create();
    }
}
